Given /^a potential email user$/ do
  browser.goto('http://www.gmail.com')
end

When /^clicks sign-up link$/ do
  begin
    browser.link(:text, /Sign up/i).click
  rescue
	raise "YOU ARE ALREADY SIGNED UP AND IN FOR GMAIL: PLEASE SIGN OUT"
  end
end

When /^enters first name of '(.+)'$/ do |first_name|
  browser.text_field(:id, /FirstName/).set(first_name)
end

When /^surname of '(.+)'$/ do |last_name|
  browser.text_field(:id, /LastName/).set(last_name)
end

When /^submit$/ do
  browser.button(:id, /submitbutton/).click
end

When /^enters all the relevant information$/ do
  When("enters first name of 'aidy'")
  When("surname of 'lewis'")
  When("enters the desired login name of 'aidy.lewis'")
  When("enters a password of 'password123'") 
  When("re-enters the password") 
  When("selects a security question of 'What was your first teacher's name'")
  When("enters a security answer of 'Miss First Teacher'")
  When("enters a secondary email of 'aidy.lewis@mcfc.co.uk'")
  When("selects a location of 'United Kingdom'")
  When("enters a word verification of 'notachance'") 
  When("submit")
end

When /^enters the desired login name of '(.+)'/ do |desired_login_name|
  browser.text_field(:id, /Email/).set(desired_login_name)
end

When /^enters a password of '(.+)'/ do |password|
  @password = password
  browser.text_field(:id, /Passwd/).set(@password)
end

When /^re-enters the password$/ do
  browser.text_field(:id, /PasswdAgain/).set(@password)
  @password = nil
end

When /^selects a security question of '(.+)'$/ do |security_question|
  browser.select_list(:id, /questions/).select(security_question)
end

When /^enters a security answer of '(.+)'$/ do |security_answer|
  browser.text_field(:id, /IdentityAnswer/).set(security_answer)
end

When /^enters a secondary email of '(.+)'$/ do |secondary_email|
  browser.text_field(:id, /SecondaryEmail/).set(secondary_email)
end

When /^selects a location of '(.+)'$/ do |country|
  browser.select_list(:id, /loc/).select(country)
end
 
When /^enters a word verification of '(.+)'$/ do |word_verification|
  browser.text_field(:id, /newaccountcaptcha/).set(word_verification)
end

Then /^I should not be allowed an email account$/ do
  browser.text.should include("Required field cannot be left blank")
end

Then /^the user should be accepted to gmail$/ do
  browser.text.should include("You have a new gmail account")
end